$(function () {

  template.defaults.imports.formatDate = function (date) {
    date = new Date(date)
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    var day = date.getDate()
    return year + '-' + month + '-' + day
  }

  function comm() {
    $.ajax({
      type: "GET",
      url: "admin/comments",
      success: function (res) {
        let htmlStr = template('commJs', res);
        $('tbody').html(htmlStr)
      }
    })
  }
  comm();
  $('tbody').on("click", 'button:contains("删除")', function () {
    let id = $(this).data('id');
    $.ajax({
      type: "DELETE",
      url: 'admin/comments/' + id,
      success: function (res) {
        if (res.status === 0) {
          comm();
        }
      }
    })
  })
})

